package com.n9.qq.android.login.tlv;

import com.n9.qq.util.Util;

import java.util.Objects;

/**
 * @author ice
 * @since 2019/2/12 15:20
 */
public class Tlv0128 extends BaseTlv {
    int len;
    public Tlv0128() {
        this.cmd = 0x0128;
    }

    /**
     * @param var1          final 0
     * @param var2          final 1
     * @param var3          final 0
     * @param var4          final 0x01000000
     * @param phoneBrands     手机型号
     * @param imeiMd5
     * @param phoneBrands     手机品牌
     * @return
     */
    public byte[] getData(int var1, int var2, int var3, int var4, byte[] phoneType, byte[] imeiMd5, byte[] phoneBrands) {
        if (Objects.isNull(phoneType)) {
            phoneType = new byte[0];
        }
        if (Objects.isNull(imeiMd5)) {
            imeiMd5 = new byte[0];
        }
        if (Objects.isNull(phoneBrands)) {
            phoneBrands = new byte[0];
        }

        final int phoneTypeLen = phoneType.length;
        final int imeiMd5Len = imeiMd5.length;
        final int phoneBrandsLen = phoneBrands.length;
        this.len = 9 + 2 + phoneTypeLen + 2 + imeiMd5Len + 2 + phoneBrandsLen;

        int index = 0;
        byte[] data = new byte[this.len];
        Util.int16_to_buf(data, index, 0);
        index += 2;
        Util.int8_to_buf(data, index, var1);
        index++;
        Util.int8_to_buf(data, index, var2);
        index++;
        Util.int8_to_buf(data, index, var3);
        index++;
        Util.int32_to_buf(data, index, var4);
        index += 4;

        Util.int16_to_buf(data, index, phoneTypeLen);
        index += 2;
        System.arraycopy(phoneType, 0, data, index, phoneTypeLen);
        index += phoneTypeLen;

        Util.int16_to_buf(data, index, imeiMd5Len);
        index += 2;
        System.arraycopy(imeiMd5, 0, data, index, imeiMd5Len);
        index += imeiMd5Len;

        Util.int16_to_buf(data, index, phoneBrandsLen);
        index += 2;
        System.arraycopy(phoneBrands, 0, data, index, phoneBrandsLen);
        return this.getBufData(data);
    }

}
